package com.bua.datafactory;

import com.bua.dao.DentistItem;
import com.bua.dao.JGSItem;
import com.bua.toothfactory.config.Config;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created with IntelliJ IDEA.
 * User: ningning
 * Date: 13-7-2
 * Time: 下午9:44
 * To change this template use File | Settings | File Templates.
 */
public class EquipmentDataFactory extends DataFactory {
    public String DepartmentId;
    public String DepartmentName;
    public String Hospital;
    public DentistItem[] dentist;
    public JGSItem[] JGS;

    public EquipmentDataFactory(String jsonString) {
        super(jsonString);
        if (status == 200) {
            try {
                JSONObject Department=body.getJSONObject("Department") ;
                DepartmentId = Department.getString("department_id");
                DepartmentName = Department.getString("department_name");
                Hospital= Department.getString("hospital");
                JSONArray Dentists = body.getJSONArray("Dentists");
                JSONArray Workers = body.getJSONArray("Workers");
                int dentistCount = Dentists.length();
                int JGSCount = Workers.length();
                dentist = new DentistItem[dentistCount];
                JGS     =  new JGSItem[JGSCount] ;
                Config.DentistList = new String[dentistCount];
                Config.JGSList = new String[JGSCount];
                for (int index = 0; index < dentistCount; index++) {
                    DentistItem item=new   DentistItem();
                    item.DentistId= Dentists.getJSONObject(index).getString("id");
                    item.DentistName  = Dentists.getJSONObject(index).getString("username");
                    dentist[index]=item;
                    Config.DentistList[index] = dentist[index].DentistId + " " + dentist[index].DentistName;
                }

                for (int index = 0; index < JGSCount; index++) {

                    JGSItem item=new  JGSItem();
                    item.JGSId = Workers.getJSONObject(index).getString("id");
                    item.JGSName = Workers.getJSONObject(index).getString("username");
                    JGS[index]=   item;
                    Config.JGSList[index] = JGS[index].JGSId + " " + JGS[index].JGSName;
                }

            } catch (JSONException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }


        }

    }
}
